/**
 * 给定年月日，问第二天的日期
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>

using llt = long long;
using vi = vector<int>;

int M, D;
int y, m, d;

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> M >> D >> y >> m >> d;
    if(m == M){
        if(d == D) return cout << y + 1 << " 1 1" << endl, 0;
        return cout << y << " " << m << " " << d + 1 << endl, 0; 
    }
    if(d == D) return cout << y << " " << m + 1 << " 1" << endl, 0;
    cout << y << " " << m << " " << d + 1 << endl;
    return 0;
}